package com.linxiao.call.controller;

import com.linxiao.call.domain.CrmTelephoneConfig;
import com.linxiao.call.service.ICrmTelephoneConfigService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用户IP话机配置Controller
 * 
 * @author zhoudong
 * @date 2022-08-24
 */
@RestController
@RequestMapping("/telephoneConfig/telephone")
public class CrmTelephoneConfigController extends BaseController
{
    @Autowired
    private ICrmTelephoneConfigService crmTelephoneConfigService;

    /**
     * 查询用户IP话机配置列表
     */
    @PreAuthorize("@ss.hasPermi('telephoneConfig:telephone:list')")
    @GetMapping("/list")
    public TableDataInfo list(CrmTelephoneConfig crmTelephoneConfig)
    {
        startPage();
        List<CrmTelephoneConfig> list = crmTelephoneConfigService.selectCrmTelephoneConfigList(crmTelephoneConfig);
        return getDataTable(list);
    }

    /**
     * 导出用户IP话机配置列表
     */
    @PreAuthorize("@ss.hasPermi('telephoneConfig:telephone:export')")
    @Log(title = "用户IP话机配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CrmTelephoneConfig crmTelephoneConfig)
    {
        List<CrmTelephoneConfig> list = crmTelephoneConfigService.selectCrmTelephoneConfigList(crmTelephoneConfig);
        ExcelUtil<CrmTelephoneConfig> util = new ExcelUtil<CrmTelephoneConfig>(CrmTelephoneConfig.class);
        util.exportExcel(response, list, "用户IP话机配置数据");
    }

    /**
     * 获取用户IP话机配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('telephoneConfig:telephone:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(crmTelephoneConfigService.selectCrmTelephoneConfigById(id));
    }

    /**
     * 根据用户ID,查询IP话机配置详细
     */
    @GetMapping(value = "/getTelephoneByUserId/{id}")
    public AjaxResult getTelephoneByUserId(@PathVariable("id") Long userId)
    {
        return AjaxResult.success(crmTelephoneConfigService.selectCrmTelephoneConfigByUserId(userId));
    }


    /**
     * 新增用户IP话机配置
     */
    @PreAuthorize("@ss.hasPermi('telephoneConfig:telephone:add')")
    @Log(title = "用户IP话机配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CrmTelephoneConfig crmTelephoneConfig)
    {
        return toAjax(crmTelephoneConfigService.insertCrmTelephoneConfig(crmTelephoneConfig));
    }

    /**
     * 修改用户IP话机配置
     */
    @PreAuthorize("@ss.hasPermi('telephoneConfig:telephone:edit')")
    @Log(title = "用户IP话机配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CrmTelephoneConfig crmTelephoneConfig)
    {
        return toAjax(crmTelephoneConfigService.updateCrmTelephoneConfig(crmTelephoneConfig));
    }

    /**
     * 删除用户IP话机配置
     */
    @PreAuthorize("@ss.hasPermi('telephoneConfig:telephone:remove')")
    @Log(title = "用户IP话机配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(crmTelephoneConfigService.deleteCrmTelephoneConfigByIds(ids));
    }
}
